<?php
final class ConnectionFactory {
	# connection parameters
	const DB_HOST = "localhost:3350";
	const DB_NAME = "ise";
	const DB_USER = "root";
	const DB_PASS = "pyranja";
	# singleton
	private static $instance = NULL;
	public static function getInstance() {
		if (NULL === self::$instance) { self::$instance = new self;	}
		return self::$instance;
	}
	private function __construct() { /* deny construction */ }
	private function __clone() { /* deny cloning */ }
		
	# api
	public function open() {
		try {
			$DBH = new PDO("mysql:host=".self::DB_HOST.";dbname=".self::DB_NAME, self::DB_USER, self::DB_PASS);
			$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		} catch(PDOException $e) {
			echo "!! failed" . $e->getMessage() . "\n";
		}
		echo "opened connection\n";
		return $DBH;
	}
	
	public function release($conn) {
		echo "released connection\n";
		$conn = null;
	}
}
?>